package com.gator.desig_mode.mediator;

import java.util.HashMap;

/**
 * @author 何章怀晓 hezhanghuaixiao
 * @version V1.0
 * @desc 同事
 */
public abstract class Colleague {

  private Mediator mediator;

  private String name;

  public Colleague(Mediator mediator, String name) {
    this.mediator = mediator;
    this.name = name;
  }

  abstract void sendMessage(String info);

  Mediator getMediator() {
    return this.mediator;
  }

  public void setMediator(Mediator mediator) {
    this.mediator = mediator;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }
}


//闹钟
class Alarm extends Colleague {


  public Alarm(Mediator mediator, String name) {
    super(mediator, name);
    //将自己注册到map
    this.getMediator().register(name, this);
  }

  @Override
  void sendMessage(String info) {
    this.getMediator().getMessage(info, this.getName());
  }

}


//闹钟
class TV extends Colleague {

  public TV(Mediator mediator, String name) {
    super(mediator, name);
    this.getMediator().register(name, this);

  }

  void openTv() {
    System.out.println("打开电视");
  }

  @Override
  void sendMessage(String info) {
    this.getMediator().getMessage(info, this.getName());
  }

}
